using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Elo.Exemplo.EFCodeFirst.Domain.Entities;

namespace Elo.Exemplo.EFCodeFirst.Domain.Mapping
{
	public class Order_DetailMap : EntityTypeConfiguration<Order_Detail>
	{
		public Order_DetailMap()
		{
			// Primary Key
			this.HasKey(t => new { t.OrderID, t.ProductID });

			// Properties
			this.Property(t => t.OrderID)
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
				
			this.Property(t => t.ProductID)
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
				
			// Table & Column Mappings
			this.ToTable("Order Details");
			this.Property(t => t.OrderID).HasColumnName("OrderID");
			this.Property(t => t.ProductID).HasColumnName("ProductID");
			this.Property(t => t.UnitPrice).HasColumnName("UnitPrice");
			this.Property(t => t.Quantity).HasColumnName("Quantity");
			this.Property(t => t.Discount).HasColumnName("Discount");

			// Relationships
			this.HasRequired(t => t.Order)
				.WithMany(t => t.Order_Details)
				.HasForeignKey(d => d.OrderID);
				
			this.HasRequired(t => t.Product)
				.WithMany(t => t.Order_Details)
				.HasForeignKey(d => d.ProductID);
				
		}
	}
}

